DESCRIPTION = "IgH EtherCAT Master for Linux"
HOMEPAGE = "https://gitee.com/phytium_embedded/ether-cat.git"
LICENSE = "GPL-2.0-or-later"
LIC_FILES_CHKSUM = "file://COPYING;md5=59530bdf33659b29e73d4adb9f9f6552"

SRCBRANCH ?= "master"

SRC_URI = "git://gitee.com/phytium_embedded/ether-cat.git;branch=${SRCBRANCH};protocol=https"

SRCREV = "26b3c14b1130e2f5a996ae7d862ade4ae8903590"
S = "${WORKDIR}/git"

PACKAGECONFIG ??= "generic cadence"

PACKAGECONFIG[generic] = "--enable-generic,--disable-generic,"
PACKAGECONFIG[8139too] = "--enable-8139too,--disable-8139too,"
PACKAGECONFIG[e100]    = "--enable-e100,--disable-e100,"
PACKAGECONFIG[e1000]   = "--enable-e1000,--disable-e1000,"
PACKAGECONFIG[e1000e]  = "--enable-e1000e,--disable-e1000e,"
PACKAGECONFIG[r8169]   = "--enable-r8169,--disable-r8169,"
PACKAGECONFIG[cadence] = "--enable-cadence,--disable-cadence"


do_configure:prepend() {
    touch ${S}/ChangeLog
}

do_configure[depends] += "virtual/kernel:do_shared_workdir"

inherit autotools-brokensep pkgconfig module-base

EXTRA_OECONF += "--with-linux-dir=${STAGING_KERNEL_BUILDDIR}"
EXTRA_OECONF += "--with-module-dir=kernel/ethercat"

do_compile:append() {
	oe_runmake modules
}

inherit systemd
do_install:append() {
	oe_runmake MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} modules_install
	rm -rf ${D}${sysconfdir}/init.d/ethercat
        install -d  ${D}${datadir}/examples/dc_user/
	if [ ! -z "${PACKAGECONFIG}" ]; then
		if [ ! -d ${D}${sysconfdir}/modprobe.d ]; then
			mkdir ${D}${sysconfdir}/modprobe.d
		fi
		if [ ! -e ${D}${sysconfdir}/modprobe.d/igh-ethercat.conf ]; then
			touch ${D}${sysconfdir}/modprobe.d/igh-ethercat.conf
		fi
		for var in ${PACKAGECONFIG}
		do
			echo "blacklist ec_${var}" >> ${D}${sysconfdir}/modprobe.d/igh-ethercat.conf
		done
	fi
        install -m 0755 ${S}/examples/dc_user/ec_dc_user_example ${D}${datadir}/examples/dc_user/
}

FILES:${PN} += "${nonarch_base_libdir}/modules/${KERNEL_VERSION}/* ${systemd_system_unitdir}/ethercat.service ${bindir_native}/* ${sbindir_native}/* ${libdir_native}/* ${sysconfdir_native}/*  ${datadir}/bash-completion/completions/ethercat ${datadir}/examples/dc_user/*"
SYSTEMD_SERVICE_ethercat = "ethercat.service"
SYSTEMD_AUTO_ENABLE = "disable"

INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
